package server4;

import java.io.IOException;
import java.net.ServerSocket;

import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Server {
	private ServerSocket sSocket;
	private int portR;
	public static String SERVER_NAME = "Server 4";
	public static int ISERVER = 4;

	private JFrame frameJF;
	protected static JTextArea infoJTA;
	private JScrollPane infoJSP;
	private JProgressBar progressJPB;

	public Server(int portL, int portR) {

		try {
			this.sSocket = new ServerSocket(portL);
			this.portR = portR;

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		frameJF = new JFrame(Server.SERVER_NAME);
		frameJF.setSize(300, 400);
		frameJF.setLayout(null);
		frameJF.setResizable(false);
		
		infoJTA = new JTextArea("Dang cho tai cong 2014...");
		infoJSP = new JScrollPane(infoJTA,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		infoJSP.setLocation(10, 15);
		infoJSP.setSize(275, 320);
		frameJF.add(infoJSP);
		
		progressJPB = new JProgressBar();
		progressJPB.setLocation(10, 345);
		progressJPB.setSize(275, 15);
		progressJPB.setIndeterminate(true);
		frameJF.add(progressJPB);
		
		frameJF.setVisible(true);

	}

	public void open() {
		try {
			while (true) {
				new Thread(new Process(this.sSocket.accept(), this.portR))
						.start();
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		Server server1 = new Server(2014, 2015);
		server1.open();
	}
}
